package cn.iocoder.yudao.module.biz.service.licence;

/**
 * @author 陈浩
 * @date 2022/4/17
 */

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.StringJoiner;


public class SequenceUtil {

    static final int DEFAULT_LENGTH = 4;

    /**
     * 格式化 key
     * @param seq
     * @return
     */
    public static String getSequence(Long seq) {
        String str = String.valueOf(seq);
        int len = str.length();
        // 取决于业务规模
        if (len >= DEFAULT_LENGTH) {
            return str;
        }
        int rest = DEFAULT_LENGTH - len;
        StringJoiner stringJoiner = new StringJoiner("");
        for (int i = 0; i < rest; i++) {
            stringJoiner.add("0");
        }
        stringJoiner.add(str);
        return stringJoiner.toString();
    }

    /**
     * 获取当前年月日
     * @return
     */
    public static String getCurrentDate(){
        LocalDate localDate = LocalDate.now();
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd");
        return df.format(localDate);
    }
}

